package com.flkin.security;

import com.flkin.common.utils.SecurityUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author yanxiang.huang
 */
@Service("sec")
public class ISecurity {

    public final static String ROLE_ADMIN = "ROLE_ADMIN";

    public boolean check(String... authorities) {
        Set<String> authorityList = SecurityUtils.getCurrentUser().getAuthorities().stream()
                .map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
        return authorityList.contains(ROLE_ADMIN) || Arrays.stream(authorities).anyMatch(authorityList::contains);
    }

}
